/**
 * Copyright 2010 The Regents of the University of California
 *
 *  All Rights Reserved
 */

#ifndef _NEW_SWITCH_HANDLER_H
#define _NEW_SWITCH_HANDLER_H 1

#include "rconn.h"
#include "learning-switch.h"
#include "openflow/openflow.h"
#include "packets.h"
#include "build-fattree.h"
#include "dcswitch.h"


#define CORE 2
#define AGGR 1
#define EDGE 0


#define ETH_IP_TYPE 0x0800
#define ICMP_ECHO_REQ 8

extern int sw_indexTmp;

typedef struct probe_packet
{
	struct eth_header header;
	uint8_t sw_indexTmp;
	uint8_t sw_index;
	uint8_t port;
}probe_pkt;

struct rconn;
struct lswitch;

typedef struct dcSwitch {
	struct rconn* rconn;
	struct lswitch *sw;
	int n_ports;
	int internal_ports;             // Ports excluding those connected to the host. These are ones which build the fat tree
	
	unsigned long long int datapath_id;
	uint8_t hw_addr[ETH_ADDR_LEN];
	int index;
	int fattree_index;
	int sw_indexTmp;
	int level;
	int pod;
	int ports[K][2];
	struct dcSwitch* neighbours[K];
}DCSwitch_node;

typedef struct location {
	int pod;
	int position;
	int port;
	int vmid;
}location;

DCSwitch_node* DCSwitches[MAX_SWITCHES];

void add_new_switch(struct lswitch *sw, struct rconn *rconn, struct ofp_switch_features *osf);
void handle_probe_packet(struct lswitch* sw, struct ofp_packet_in* _opi);
void catchAlarm(int);
void catchSwitchDiscoveryTimeout(int);
bool isDownwordFacing(int switchIndex, int port);
void send_probe_packet_out(struct lswitch *sw, struct rconn *rconn, uint16_t in_port, int out_ports, DCSwitch_node* node);
#endif
